<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user_model
 *
 * @author hassanali
 */
class user_model extends cms_model {

    public function __construct() {
        parent::__construct();
        $this->table = 'user';
    }

    //put your code here

    public function login($username, $password) {
        $user = $username;
        $regex = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+^";
        if (preg_match($regex, $username))
            $data['email'] = $user;
        else
            $data['username'] = $user;
        $data['password'] = md5($password);
        $data['trash'] = 'NO';
        $data['mode'] = 'user';
        $sql = $this->db->get_where($this->table, $data);
        if ($sql->num_rows()) {
            $user = $sql->row();
            return $user;
        } else {
            return false;
        }
    }

    public function reset($email, $code, $password) {
        $user = get_userid_with_email($email, 'where');
        $password = md5($password);
        $this->db->update('users', array('password' => $password), array('id' => $user[0]));
        //$this->email_system->SendSingelEmail('',$user[0], 'forget', 'طلب استعادة كلمة المرور', array('{Forget_Code}' => $code));
    }

    public function update_user_login($id) {
        $this->db->update($this->table, array('last_login' => date("Y-m-d H:i:s")), array('id' => $id));
    }

}

?>
